package 多线程.多线程创建.线程安全.同步方法;

import java.util.ArrayList;
import java.util.List;

public class MyTicket implements Runnable {
    private static int ticket = 3;

    @Override
    public void run() {
        sub();
    }

    public static synchronized void sub() {
        while (true) {
            if (ticket < 0 || ticket == 0) {
                return;
            }
            System.out.println(Thread.currentThread().getName() + "抢到了第" + ticket + "张票");
            --ticket;
        }
    }
}
